﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_BbsManage_ReManageList : Baimasoft.Web.UI.PageManagerTop
{
    CMods MyCM = new CMods();
    Replies MyRL = new Replies();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindControlEvent();

        this.HiddenID.Value = "";
        if (!this.IsPostBack)
        {
            try
            {
                AspNetHelper.IndexPageLoad(this, this.Indicator); //导航
                AspNetHelper.BtnGrantInfo(this);  //按钮控制   注意前后加载顺序: 先加载导航,后加载按钮控制; 页面加载顺序是从上向下加载的
            }
            catch
            {
            }
            SectionNameDrpBind();
            this.BindGridViewData();//绑定GridView,为删除服务
        }
    }

    protected override void BindGridViewData()
    {
        this.DataSource = MyRL .GetRepliesInfos (GetSearchString());
        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();
    }

    public void SectionNameDrpBind()
    {
        SectionNameDrp.DataSource = MyCM.GetCModsInfo("a.Visiable='1'");
        SectionNameDrp.DataBind();
        SectionNameDrp.Items.Insert(0, "全部大类");
        SectionNameDrp.Items[0].Value = "0";
    }

    protected void Btn_3_ServerClick(object sender, EventArgs e)
    {
        try
        {
            string ids = "", sFileNameCol = "";

            System.Web.UI.HtmlControls.HtmlInputCheckBox check;

            foreach (GridViewRow row in GridView1.Rows)
            {
                check = (System.Web.UI.HtmlControls.HtmlInputCheckBox)row.FindControl("check");
                if (check.Checked)
                {
                    ids += check.Value + ",";

                    GridViewRow selectedRow = GridView1.Rows[row.RowIndex];

                    TableCell contactFE = selectedRow.Cells[1];  //Name
                    sFileNameCol += contactFE.Text.ToString().Trim();
                }
            }

            ids = ids.TrimEnd(',').ToString().Trim();

            int iback = MyRL.DeleteRepliesInfo(ids);
            if (iback < 1)
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "没有可删除的数据!");
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');location.href='ReManageList.aspx';</script>");
                return;
            }
        }
        catch
        {
            Baimasoft.Web.UI.Message.AlertMsg(this, "删除失败!");
        }
    }


    protected override string GetSearchString()
    {
        string searchStr = string.Empty;
        string sSectionID = SectionNameDrp.SelectedValue.ToString().Trim();
        string sTitle = Title.Text.ToString().Trim();

        string sSDT = SDT.Text.ToString().Trim();
        string sEDT = EDT.Text.ToString().Trim();

        string sVisiable = Visiable.SelectedValue.ToString().Trim();

        searchStr += " (1=1) ";
        if (sSectionID != "0")
        {
            searchStr += " and b.SectionID ='" + sSectionID + "' ";
        }

        if (sTitle != "")
        {
            searchStr += " and b.title like'%" + sTitle + "%' ";
        }

        if (sSDT != "")
        {
            searchStr += " and  convert(varchar(10),a.ReDT,120) >= '" + sSDT + "' ";
        }

        if (sEDT != "")
        {
            searchStr += " and  convert(varchar(10),a.ReDT,120) <= '" + sEDT + "' ";
        }
        if (sVisiable != "")
        {
            searchStr += " and a.sApproveResult = '" + sVisiable + "' ";
        }

        return searchStr;
    }
}